import { BaseService } from '@/base/base.service';
import { pageData } from '@/util/util';
import { Injectable } from '@nestjs/common';
import { newCarClue } from '@prisma/client';
import { CreateNewCarClueDto } from './dto/create-new-car-clue.dto';
import { UpdateNewCarClueDto } from './dto/update-new-car-clue.dto';

@Injectable()
export class NewCarClueService {

  constructor(private baseService: BaseService) {}

  async create(createNewCarClueDto: CreateNewCarClueDto) {
    await this.baseService.newCarClue.create({
      data: {
        ...createNewCarClueDto
      }
    })
    return '添加成功'
  }

  async findAll() {
    return await this.baseService.newCarClue.findMany();
  }

  async findPage(query: any) {
    return await pageData<newCarClue>('newCarClue', query)
  }

  async findOne(id: string) {
    return await this.baseService.newCarClue.findUnique({
      where: {
        id
      }
    });
  }

  async update(id: string, updateNewCarClueDto: UpdateNewCarClueDto) {
    await this.baseService.newCarClue.update({
      where: {
        id
      },
      data: updateNewCarClueDto
    })
    return '修改成功'
  }

  async remove(id: string) {
    await this.baseService.newCarClue.delete({
      where: {
        id
      }
    })
    return '删除成功'
  }

  manyRemove(idList: string[]) {
    idList.forEach(async item => {
      await this.remove(item)
    })
    return '删除成功'
  }

  changeLockDate(id: string, dto: { date: string }) {
    const res = this.baseService.newCarClue.update({
      where: {
        id
      },
      data: {
        startLockDate: dto.date
      }
    })
    return res
  }
}
